package com.alibaba.citrus.ots.sales.plan.facade.service.setting;

import com.alibaba.citrus.ots.common.annotation.FacadeInvoker;
import com.alibaba.citrus.ots.common.exception.FacadeException;
import com.alibaba.citrus.ots.sales.plan.api.setting.NotificationConfigQueryService;
import com.alibaba.citrus.ots.sales.plan.dto.api.request.NotificationConfigQueryRequest;
import com.alibaba.citrus.ots.sales.plan.dto.api.request.PageQueryNotificationConfigRequest;
import com.alibaba.citrus.ots.sales.plan.repository.NotificationConfigRepository;
import com.alibaba.citrus.ots.sales.plan.sdo.NotificationConfigSDO;
import com.alibaba.cz.base.tool.page.PageResult;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NotificationConfigQueryServiceImpl implements NotificationConfigQueryService {

    @Resource
    private NotificationConfigRepository notificationConfigRepository;

    @FacadeInvoker
    @Override
    public Result<PageResult<List<NotificationConfigSDO>>> pageQueryNotificationConfig(PageQueryNotificationConfigRequest pageQueryNotificationConfigRequest) {
        if (pageQueryNotificationConfigRequest.getBizType() == null && StringUtils.isBlank(pageQueryNotificationConfigRequest.getBizId())) {
            throw new FacadeException("OTS-01-001-01-15-021");
        }
        PageResult<List<NotificationConfigSDO>> listPageResult = notificationConfigRepository.pageQuery(pageQueryNotificationConfigRequest);
        return Result.success(listPageResult);
    }

    @Override
    @FacadeInvoker
    public Result<NotificationConfigSDO> queryNotificationConfigById(NotificationConfigQueryRequest notificationConfigQueryRequest) {
        NotificationConfigSDO notificationConfigSDO= notificationConfigRepository.queryNotificationConfigById(notificationConfigQueryRequest);
        return Result.success(notificationConfigSDO);
    }

    @Override
    public Result<PageResult<List<NotificationConfigSDO>>> queryMailTemplate(PageQueryNotificationConfigRequest pageQueryNotificationConfigRequest) {
        PageResult<List<NotificationConfigSDO>> listPageResult = notificationConfigRepository.pageQueryMailTemplate(pageQueryNotificationConfigRequest);
        return Result.success(listPageResult);
    }
}
